package config

import (
	"fmt"
	"io/ioutil"

	"gitee.com/RocsSun/report/constants"
	"gitee.com/RocsSun/report/models"
	"gopkg.in/yaml.v2"
)

var ConfigContext *models.ConfigModel

func init() {
	ConfigContext = &models.ConfigModel{}
	fileBytes, err := ioutil.ReadFile(constants.ConfigPath)
	if err != nil {
		panic(err.Error())
	}

	if err = yaml.Unmarshal(fileBytes, ConfigContext); err != nil {
		panic(err.Error())
	}
}

func ReadMachineList() {
	ConfigContexts := []models.Machine{}
	fileBytes, err := ioutil.ReadFile(constants.MachineConfigPath)
	if err != nil {
		panic(err.Error())
	}

	if err = yaml.Unmarshal(fileBytes, &ConfigContexts); err != nil {
		panic(err.Error())
	}
	fmt.Println(ConfigContexts[0])
}

func ReadNetFlowList() map[string][]*models.NetFlowNodes {
	var ConfigContexts map[string][]*models.NetFlowNodes = make(map[string][]*models.NetFlowNodes)

	fileBytes, err := ioutil.ReadFile(constants.NetFlowRestAPIConfigPath)
	if err != nil {
		panic(err.Error())
	}

	if err = yaml.Unmarshal(fileBytes, &ConfigContexts); err != nil {
		panic(err.Error())
	}
	return ConfigContexts
}
